package org.e_gold.dao.impl;

import org.e_gold.dao.EventDAO;
import org.e_gold.model.Event;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class EventDAOImpl extends AbstractGenericDAO<Event> implements EventDAO {

    public EventDAOImpl() {

        super(Event.class);
    }

    @Override
    @Transactional
    public Event findByName(String name) {

        Event retval = null;
        Criteria criteria = getCurrentSession().createCriteria(Event.class);
        criteria.setFirstResult(0);
        criteria.add(Restrictions.like(Event.NAME, name));
        if (criteria.list() != null && criteria.list().size() > 0) {
            retval = (Event) criteria.list().get(0);
        }
        return retval;
    }
}
